import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2{
    private String name;
    private int age;

    public PersonSortable2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return name+"-"+age;
    }
}
class NameComparator implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        PersonSortable2 p1=(PersonSortable2) o1;
        PersonSortable2 p2=(PersonSortable2) o2;
        return p1.getName().compareTo(((PersonSortable2) o2).getName());
    }
}
class AgeComparator implements Comparator{
    @Override
    public int compare(Object o1, Object o2) {
        PersonSortable2 p1=(PersonSortable2) o1;
        PersonSortable2 p2=(PersonSortable2) o2;
        int a=p1.getAge()-p2.getAge();
        if (a>0){
            return 1;
        }else if (a==0){
            return 0;
        }else {
            return -1;
        }
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=Integer.valueOf(sc.nextLine());
        PersonSortable2[] arr=new PersonSortable2[count];
        for (int i=0;i<count;i++){
            String str[]=sc.nextLine().split(" ");
            arr[i]=new PersonSortable2(str[0],Integer.valueOf(str[1]));
        }
        System.out.println("NameComparator:sort");
        NameComparator nameComparator = new NameComparator();
        Arrays.sort(arr,nameComparator);
        for (int i=0;i<count;i++){
            System.out.println(arr[i]);
        }
        System.out.println("AgeComparator:sort");
        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(arr,ageComparator);
        for (int i=0;i<count;i++){
            System.out.println(arr[i]);
        }
        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
    }
}

